package com.zrwl.poscloud.core.restapi.mobile;

import com.zrwl.poscloud.base.constants.TransitConstants;
import com.zrwl.poscloud.commons.exception.ThrowableUtils;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.validator.group.GetList;
import com.zrwl.poscloud.commons.validator.group.Update;
import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;
import com.zrwl.poscloud.xo.service.TransitService;
import com.zrwl.poscloud.xo.service.UserService;
import com.zrwl.poscloud.xo.vo.TransitVO;
import com.zrwl.poscloud.xo.vo.UserEmployeeRVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 出校管理 controller api类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-03-17
 */
@RestController
@Api(value = "出校管理相关接口", tags = {"出校管理相关接口"})
@RequestMapping("/userTransit")
@Slf4j
public class EnterAndExitTheCampusRestApi {
    @Autowired
    private TransitService transitService;
    @Autowired
    private UserService userService;
    @AuthorityVerify
    @ApiOperation(value = "获取最近一次出校入校记录", notes = "获取最近一次出校入校记录", response = String.class)
    @PostMapping("/getLastTimeTransitList")
    public String getLastTimeTransitList(@Validated({GetList.class}) @RequestBody TransitVO transitVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取出校管理列表: {}", transitVO);
        UserEmployeeRVO userEmployeeRVO = userService.getMe().getUserEmployeeRVO();
        transitVO.setEmployeeUid(userEmployeeRVO.getEmployeeUid());
        return ResultUtil.successWithData(transitService.getLastTimeTransitList(transitVO));
    }
    @AuthorityVerify
    @ApiOperation(value = "获取出校管理列表", notes = "获取出校管理列表", response = String.class)
    @PostMapping("/getAllList")
    public String getAllList(@Validated({GetList.class}) @RequestBody TransitVO transitVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取出校管理列表: {}", transitVO);
        UserEmployeeRVO userEmployeeRVO = userService.getMe().getUserEmployeeRVO();
        transitVO.setEmployeeUid(userEmployeeRVO.getEmployeeUid());
        return ResultUtil.successWithData(transitService.getAllList(transitVO));
    }
    @AuthorityVerify
    @ApiOperation(value = "获取当前出校信息", notes = "获取当前出校信息", response = String.class)
    @PostMapping("/getRecentlyHomeSchoolInfo")
    public String getRecentlyHomeSchoolInfo(@Validated({GetList.class}) @RequestBody TransitVO transitVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取当前出校信息: {}", transitVO);
        UserEmployeeRVO userEmployeeRVO = userService.getMe().getUserEmployeeRVO();
        transitVO.setEmployeeUid(userEmployeeRVO.getEmployeeUid());
        transitVO.setStatus(TransitConstants.enable);
        return ResultUtil.successWithData(transitService.getRecentlyHomeSchoolInfo(transitVO));
    }
    @AuthorityVerify
    @ApiOperation(value = "获取出校信息", notes = "获取出校信息", response = String.class)
    @PostMapping("/getHomeSchoolInfo")
    public String getHomeSchoolInfo(@Validated({GetList.class}) @RequestBody TransitVO transitVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取出校信息: {}", transitVO);
        UserEmployeeRVO userEmployeeRVO = userService.getMe().getUserEmployeeRVO();
        transitVO.setEmployeeUid(userEmployeeRVO.getEmployeeUid());
        return ResultUtil.successWithData(transitService.getHomeSchoolInfo(transitVO));
    }
    @AuthorityVerify
    @ApiOperation(value = "通知家长", notes = "通知家长", response = String.class)
    @PostMapping("/noticeParents")
    public String noticeParents(@Validated({Update.class}) @RequestBody TransitVO transitVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("通知家长: {}", transitVO);
        UserEmployeeRVO userEmployeeRVO = userService.getMe().getUserEmployeeRVO();
        transitVO.setEmployeeUid(userEmployeeRVO.getEmployeeUid());
        return transitService.handleTransitNoticeParents(transitVO);
    }
    @AuthorityVerify
    @ApiOperation(value = "通知教师", notes = "通知教师", response = String.class)
    @PostMapping("/noticeTeacher")
    public String noticeTeacher(@Validated({Update.class}) @RequestBody TransitVO transitVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("通知教师: {}", transitVO);
        UserEmployeeRVO userEmployeeRVO = userService.getMe().getUserEmployeeRVO();
        transitVO.setEmployeeUid(userEmployeeRVO.getEmployeeUid());
        return transitService.handleTransitNoticeTeacher(transitVO);
    }
    @AuthorityVerify
    @ApiOperation(value = "手机端分页获取出校管理列表", notes = "手机端分页获取出校管理列表", response = String.class)
    @PostMapping("/getAllOutOfSchoolList")
    public String getAllOutOfSchoolList(@Validated({GetList.class}) @RequestBody TransitVO transitVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("手机端分页获取出校管理列表: {}", transitVO);
        UserEmployeeRVO userEmployeeRVO = userService.getMe().getUserEmployeeRVO();
        transitVO.setEmployeeUid(userEmployeeRVO.getEmployeeUid());
        return ResultUtil.successWithData(transitService.getAllOutOfSchoolList(transitVO));
    }
}
